package actions.members;

import veilingAware.UserAware;
import veilingDomein.Bieding;
import veilingDomein.BiedingException;
import veilingDomein.User;
import veilingDomein.Veiling;
import veilingService.IBiedingService;
import veilingService.IVeilingService;
import veilingService.ServiceProvider;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class Bied extends ActionSupport implements UserAware {
	private int veilingId;
	private int bod;
	private User user;
	private IVeilingService vs = ServiceProvider.getVeilingService();
	private IBiedingService ibs = ServiceProvider.getBiedingService();

	
	private Veiling veiling;
	private Bieding hb;
	private String naam;
	private String beschrijving;
	private int hoogsteBod;

	public String execute() throws BiedingException {
		Veiling veiling = vs.getVeilingByID(veilingId);
		if (veiling != null) {
			try {
				veiling.addBieding(new Bieding(bod, user, veiling));
			} catch (BiedingException e) {
				addActionMessage(e.getMessage());
				//addFieldError("bod", e.getMessage());
				return ActionSupport.INPUT;
			}
		}
		return ActionSupport.SUCCESS;
	}

	public void validate() {
		

	}

	@Override
	public void setUser(User user) {
		this.user = user;
	}

	public void setBod(int bod) {
		this.bod = bod;
	}

	public void setVeilingId(int veilingId) {
		this.veilingId = veilingId;
	}
	
	public int getVeilingId(){
		return veilingId;
	}
	
	public User getUser(){
		return user;
	}
}
